const Router = require('koa-router');
const router = new Router();
const {db, QueryTypes} = require("../../models/db");

router.post('/sale/recentAccount', async ctx => {
    let buId = ctx.request.body.buId;
    let tenantId = ctx.user.tenantId;
    let sql = `select top 1 a.accId,b.name accName from invoice a inner join category b on a.tenantId=b.tenantId and a.accId=b.id where a.tenantId=${tenantId} `
    if(buId) sql += ` and a.buId=${buId} `
    sql += ` and a.accId <>0 order by a.id desc  `
    let list = await db.query(sql, {type: QueryTypes.SELECT})
    return ctx.suc('', list)
})



module.exports = router;
